<?php
namespace app\ice\model;
use think\Db;
use think\Model;
use think\Cache;

class Index extends Model
{
    protected $table = 'ig_goods';
    // 查看首页详情
    public function getListData($level)
    {
        $cache = Cache::get('licensePlate');
        if($cache){
            return $cache;
        }
        if($level){
            $where['level'] = $level;
        }else{
            $where['level'] = ['gt',$level];
        }
        $data = $this->name('area')
            ->where('status',1)
            ->where($where)
            // ->order('sort desc')
            ->select();
            if(!$level){
                $data = getTreeDataPhp($data);
            }
        Cache::set('licensePlate',$data);
        return $data;
    }

    // 查看首页详情
    public function getDetailData($id)
    {
        $data = $this->name('slzd_rrb_list')
            ->where('status',1)
            ->where('id',$id)
            ->order('sort desc')
            ->select();
        return $data;
    }

    public function getList($data,$page,$orll_page)
    {
        $list['row'] = $this->name('goods')
            ->page($page,$orll_page)
            ->field(['id','pic','goods_name','price'])
            ->where('status',1)
            ->select();
        $total = $this->name('goods')
            ->where('status',1)
            ->count();
        $list['count'] = ceil($total/$orll_page);
        $list['page'] = $page;
        if(count($list['row']) < 1 ){
            return false;
        }
        foreach ($list['row'] as $key => &$value) {
            $value['pic'] = config('host').$value['pic'];
        }
        return $list;
    }
}